package com.example.controller;

import com.example.common.Result;
import com.example.entity.College;
import com.example.service.CollegeService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/college")
public class CollegeController {
    @Resource
    private CollegeService collegeService;

    @GetMapping("/selectAll")
    public Result selectAll(College college){
        List<College> list = collegeService.selectAll(college);
        return Result.success(list);
    }

    @GetMapping("/selectPage")
    public Result selectPage(College college,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<College> pageInfo = collegeService.selectPage(college,pageNum,pageSize);
        return Result.success(pageInfo);
    }
    @PostMapping("/insert")
    public Result add(@RequestBody College college){
        collegeService.add(college);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody College college){
        collegeService.update(college);
        return Result.success();
    }

    @DeleteMapping("/delete/{collegeId}")
    public Result delete(@PathVariable Integer collegeId){
        collegeService.delete(collegeId);
        return Result.success();
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        collegeService.deleteBatch(ids);
        return Result.success();
    }
}
